#https://titanmatrix.com/tgxx

import requests,json,hashlib
import time


def md5(xx):
    return hashlib.md5(xx.encode()).hexdigest()

headers = {
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
    'Accept': 'application/json, text/plain, */*',
    'apiVersion': '1.0',
    'Content-Type': 'application/json;charset=UTF-8',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
    'sec-ch-ua-platform': '"Windows"',
    'Origin': 'https://titanmatrix.com',
    'Sec-Fetch-Site': 'same-site',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Referer': 'https://titanmatrix.com/',
    'Accept-Language': 'zh-CN,zh;q=0.9',
}

data = {
    "appid": "201010",
    "client": {
        "system": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36",
        "version": "1.0.0"
    },
    "param": {
        "serviceId": "a4966e02741c4cc091fe1834d00f149c",
        "sid": 7017,
        "pkey": "",
        "withParam": True,
        "noWaterMark": True
    },
    "timestamp":time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()),
    "rank": "9018048684590414",
    "sign": ""
}

enc_data = "appid=" + data['appid'] + "&client=" + json.dumps(data['client'],separators=(',',':')) + "&param=" + json.dumps(data['param'],separators=(',',':')) \
           + "&rank=" + data['rank'] + "&timestamp=" + data['timestamp'] + "&token=" + ""+ "&key=" + "72933362EAA649B893699E6191BC898F"
print(enc_data)
sign = md5(enc_data)
print(sign)
data['sign'] = sign
response = requests.post('https://macafe.titanmatrix.com/macafe/getState', headers=headers, data=json.dumps(data,separators=(',',':')))
print(response.text)